package com.lemonPiggy.UDForm.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.lemonPiggy.UDForm.domain.UDFormApplication;
import com.lemonPiggy.UDForm.service.IUDFormApplicationService;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 应用Controller
 *
 * @author ruoyi
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/application")
public class UDFormApplicationController extends BaseController {
    @Autowired
    private IUDFormApplicationService UDFormApplicationService;
    /**
     * 查询应用列表
     */
    @PreAuthorize(hasPermi = "lemonPiggy-UDForm:application:list")
    @GetMapping("/list")
    @ApiOperation(value = "应用查询", nickname = "list")
    public TableDataInfo list(UDFormApplication UDFormApplication)
    {
        startPage();
        List<UDFormApplication> list = UDFormApplicationService.selectUDFormApplicationList(UDFormApplication);
        return getDataTable(list);
    }

    /**
     * 导出应用列表
     */
    @PreAuthorize(hasPermi = "lemonPiggy-UDForm:application:export")
    @Log(title = "应用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UDFormApplication UDFormApplication) throws IOException
    {
        List<UDFormApplication> list = UDFormApplicationService.selectUDFormApplicationList(UDFormApplication);
        ExcelUtil<UDFormApplication> util = new ExcelUtil<UDFormApplication>(UDFormApplication.class);
        util.exportExcel(response, list, "应用数据");
    }

    /**
     * 获取应用详细信息
     */
    @PreAuthorize(hasPermi = "lemonPiggy-UDForm:application:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(UDFormApplicationService.selectUDFormApplicationById(id));
    }

    /**
     * 新增应用
     */
    @PreAuthorize(hasPermi = "lemonPiggy-UDForm:application:add")
    @Log(title = "应用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid UDFormApplication UDFormApplication)
    {

        return toAjax(UDFormApplicationService.insertUDFormApplication(UDFormApplication));
    }

    /**
     * 修改应用
     */
    @PreAuthorize(hasPermi = "lemonPiggy-UDForm:application:edit")
    @Log(title = "应用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UDFormApplication UDFormApplication)
    {
        return toAjax(UDFormApplicationService.updateUDFormApplication(UDFormApplication));
    }

    /**
     * 删除应用
     */
    @PreAuthorize(hasPermi = "lemonPiggy-UDForm:application:remove")
    @Log(title = "应用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(UDFormApplicationService.deleteUDFormApplicationByIds(ids));
    }

    @PostMapping("/optionselect")
    public R<List<Map<String,Object>>> optionselect(UDFormApplication UDFormApplication)
    {
        List<Map<String, Object>> maps = UDFormApplicationService.optionselect(UDFormApplication);
        return R.ok(maps);
    }


}
